package csu.softwaremetric.controller;

import com.alibaba.fastjson.JSONObject;
import csu.softwaremetric.entity.UFC;
import csu.softwaremetric.entity.VAF;
import csu.softwaremetric.service.FPService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/fp")
public class FPController {
    @Autowired
    private FPService fpService;

    @PostMapping("/UFC")
    public ResponseEntity<JSONObject> calUFC(@RequestBody UFC ufc) {
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("STATUS", "SUCCESS");
        jsonObject.put("UFC", fpService.calUFC(ufc));
        return new ResponseEntity<>(jsonObject, HttpStatus.OK);
    }

    @PostMapping("/VAF")
    public ResponseEntity<JSONObject> calVAF(@RequestBody VAF vaf) {
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("STATUS", "SUCCESS");
        jsonObject.put("VAF", fpService.calVAF(vaf));
        return new ResponseEntity<>(jsonObject, HttpStatus.OK);
    }

    @PostMapping("/FP")
    public ResponseEntity<JSONObject> calFP(@RequestBody UFC ufc, @RequestBody VAF vaf){
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("STATUS", "SUCCESS");
        jsonObject.put("FP", fpService.calFP(ufc, vaf));
        return new ResponseEntity<>(jsonObject, HttpStatus.OK);
    }
}
